package frame;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.awt.event.WindowStateListener;
import javax.swing.JFrame;
import javax.swing.UIManager;

import frame.data.contrldata;
import function.filelibrary;
import function.setting;
import function.listen.*;

@SuppressWarnings("serial")
public class master extends JFrame{
	private int winwidth=1000,winheight=700;
	public static filelibrary fl=new filelibrary();//文件库
	public static int editfilenum=0;
	public static setting set=new setting();
	//文本标签
	public static filetablisten ftl=new filetablisten();
	//编辑框
	public static textarea1listen t1l=new textarea1listen();
	//行号
	public static textarea2listen t2l=new textarea2listen();
	//公共滚动条
	public static textbarlisten tbl=new textbarlisten();
	//文件信息
	public static fileinfolisten fil=new fileinfolisten();
	//菜单
	public static menubarlisten mbl=new menubarlisten();
	//菜单1
	public static menu1listen m1l=new menu1listen();
	//菜单2
	public static menu2listen m2l=new menu2listen();
	//菜单3
	public static menu3listen m3l=new menu3listen();
	//菜单4
	public static menu4listen m4l=new menu4listen();
	//菜单5
	public static menu5listen m5l=new menu5listen();
	//菜单6
	public static menu6listen m6l=new menu6listen();
	//菜单h
	public static menuhlisten mhl=new menuhlisten();
	
	@SuppressWarnings("static-access")
	public master(String[] codeinfo) {
		this.editfilenum=fl.getfilenum()-1;
		try {
			UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
		}catch (Exception e) {
			System.exit(1);
		}
		setBounds(0, 0, winwidth,winheight);
		setLocationRelativeTo(null);
		setLayout(new BorderLayout());
		setTitle("VW-Edit V0.1.0");
		setIconImage(Toolkit.getDefaultToolkit().getImage("./material/logo/fvw.png"));
		setMinimumSize(new Dimension(400, 400));

		//加载监听
		ftl.loadfiletablisten(master.this);
		t1l.loadtextarealisten(master.this);
		mbl.loadtoolslisten();
		m1l.loadmenuitemlisten(master.this);
		m2l.loadmenuitemlisten();
		m3l.loadmenuitemlisten();
		m4l.loadmenuitemlisten(master.this);
		m5l.loadmenuitemlisten();
		m6l.loadmenuitemlisten();
		mhl.loadmenuitemlisten();
		//添加子菜单
		contrldata.tool.add(contrldata.tool1);
		contrldata.tool.add(contrldata.tool2);
		contrldata.tool.add(contrldata.tool3);
		contrldata.tool.add(contrldata.tool4);
		contrldata.tool.add(contrldata.tool5);
		contrldata.tool.add(contrldata.tool6);
		contrldata.tool.add(contrldata.toolh);
		//添加控件
		this.add(contrldata.filetab,BorderLayout.NORTH);
		this.add(contrldata.js,BorderLayout.CENTER);
		this.add(contrldata.jsl,BorderLayout.WEST);
		this.add(contrldata.fileinfo,BorderLayout.SOUTH);
		this.setJMenuBar(contrldata.tool);
		//初始化菜单icon
		m2l.updatecodeselectedformenuitem();
		
		addWindowListener(new WindowListener() {
			@Override
			public void windowOpened(WindowEvent e) {contrldata.jt.requestFocus();}
			@Override
			public void windowIconified(WindowEvent e) {}
			@Override
			public void windowDeiconified(WindowEvent e) {}
			@Override
			public void windowDeactivated(WindowEvent e) {}
			@Override
			public void windowClosing(WindowEvent e) {System.exit(0);}
			@Override
			public void windowClosed(WindowEvent e) {}
			@Override
			public void windowActivated(WindowEvent e) {}
		});
		addWindowStateListener(new WindowStateListener() {	
			@Override
			public void windowStateChanged(WindowEvent e) {
				contrldata.filetab.setPreferredSize(new Dimension(getWidth(), 30));
			}
		});
		
		setVisible(true);
	}
}
